class Solution {
public:
    int maxProfit(vector<int>& prices) 
    {
        int i = 0;
        int j;
        int sum = 0;

        for(j = i + 1; j < prices.size(); j++)
        {
            if (prices[i] < prices[j]) sum += prices[j] - prices[i];
            i++;
        }
        return sum;
    }
};